package com.wlyuan.open.controller;

import com.wlyuan.open.api.IOpenQrCodeService;
import com.wlyuan.open.vo.OpenQrCodeDetailVO;
import com.wlyuan.open.vo.OpenQrCodeVO;
import com.wlyuan.open.vo.OpenQrCodeValidateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lijing
 */
@Slf4j
@Api(tags = "二维码")
@RequestMapping("/qrcode")
@Validated
@RestController
@RequiredArgsConstructor
public class OpenQrCodeController extends BaseController {
    @DubboReference(check = false)
    private IOpenQrCodeService openQrCodeService;

    @ApiOperation("获取二维码图片")
    @GetMapping("/generate")
    public OpenQrCodeDetailVO generate() {
        return openQrCodeService.getQrcode(getAppId());
    }

    @ApiOperation("校验二维码是否有效")
    @GetMapping("/validate/{qrCodeId}")
    public OpenQrCodeValidateVO validate(@PathVariable("qrCodeId") String qrCodeId) {
        return openQrCodeService.getQrCodeValue(qrCodeId);
    }

    @ApiOperation("获取二维码扫描状态")
    @GetMapping("/{qrCodeId}")
    public OpenQrCodeVO check(@PathVariable("qrCodeId") String qrCodeId) {
        getAppId();
        return openQrCodeService.check(qrCodeId);
    }
}
